package com.example.xuzhaoyu.hotfixdemo;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

import com.meituan.robust.Patch;
import com.meituan.robust.PatchExecutor;
import com.meituan.robust.RobustCallBack;

import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        findViewById(R.id.btn_patch).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                new PatchExecutor(getApplicationContext(), new PatchManipulateImp(), new RobustCallBack() {

                    @Override
                    public void onPatchListFetched(boolean result, boolean isNet, List<Patch> patches) {
                        System.out.println("onPatchListFetched" + result + isNet + patches);
                    }

                    @Override
                    public void onPatchFetched(boolean result, boolean isNet, Patch patch) {
                        System.out.println("onPatchFetched" + result + isNet + patch.getLocalPath());
                    }

                    @Override
                    public void onPatchApplied(boolean result, Patch patch) {
                        System.out.println("onPatchApplied" + result + patch.getLocalPath());
                    }

                    @Override
                    public void logNotify(String log, String where) {
                        System.out.println("logNotify" + where);
                    }

                    @Override
                    public void exceptionNotify(Throwable throwable, String where) {
                        System.out.println("exceptionNotify" + throwable + where);
                    }
                }).start();
            }
        });
        findViewById(R.id.btn_jump).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, SecondActivity.class);
                MainActivity.this.startActivity(intent);
            }
        });
    }
}
